package com.yunhe.control;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yunhe.bean.ShopUser;
import com.yunhe.service.PingJias;

/**
 * Servlet implementation class PingJia1
 */
@WebServlet("/hou/PingJia1")
public class PingJia1 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PingJia1() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String uname = request.getParameter("username");
		if(uname!=null){
			List<ShopUser> pingJUname = new PingJias().PingJUname(uname);
			request.setAttribute("pingjia", pingJUname);
			request.getRequestDispatcher("evaluate-list.jsp").forward(request, response);
		}else{
			String page = request.getParameter("page");
			int pass2 = 0;
			if(page == null){
				pass2 = 0;
			}else{
				pass2 = Integer.parseInt(page);
			}
			
			
			PingJias pj = new PingJias();
			
			List<ShopUser> fenPingjia = pj.FenPingjia(pass2*3);//获取的每页的数据集合
			int zongtiao = pj.PingJ().size();
			int zongye = zongtiao%3 == 0?zongtiao/3:zongtiao/3+1;
			
			request.getSession().setAttribute("curr", pass2);
			
			request.getSession().setAttribute("zongye", zongye-1);
			
			request.setAttribute("pingjia", fenPingjia);
			request.getRequestDispatcher("evaluate-list.jsp").forward(request, response);
		}
		
		
		
	}

}
